<?
// Database Connection
$dbname = 'tcntrans_main';
$dbhost = 'localhost';
$dbuser = 'tcntrans';
$dbpass = 'hJV65VUX';
$db = mysql_connect($dbhost,$dbuser,$dbpass);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>New document</title>
<meta name="generator" content="TSW WebCoder">
</head>

<body>
<h1>Updating Link Paths</h1>
<?
$row = 1;
$handle = fopen("StudentUpdates1.csv", "r");
$count=0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    $row++;
    
    $levelID  = $data[0];
    $linkID   = $data[1];
    $spoke    = $data[2]; 
    
    // Update database
    // First, let's see if this PathLink even exists
    $sql1 = "SELECT * from transLinkPath WHERE LinkID = '$linkID' AND PathID = '$levelID'";
    $result1 = mysql_db_query($dbname,$sql1); 
    
    if (mysql_num_rows($result1)<1) {
	    $sql = "INSERT into transLinkPath (
					LinkID,
					PathID,
					MainPath,
					Userid
					) values  (
					'$linkID',
					'$levelID',
					'/$spoke',
					'1'
					)";
	    $result = mysql_db_query($dbname,$sql); 
	    echo 'Adding PathLink for LinkID: '.$linkID.' PathID: '.$levelID.'<br />';
	    echo $sql.'<br />';
	    $count++;
	}  
}
echo '<b>'.$count.' records added</b>';
fclose($handle);
?>


</body>
</html>